﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GCELibrary.Current
{
    /// <summary>
    /// 单例模式模板
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Singleton<T> where T : new()
    {
        private static T _instance;
        private static object objLock = new object();
        public Singleton()
        {

        }
        /// <summary>
        /// 返回实例
        /// </summary>
        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    //获得实例，使用这个方法的前提是T要有公有的、无参数的构造函数               
                    _instance = (T)System.Activator.CreateInstance(typeof(T));
                }
                return _instance;
            }
             
        }
    }
}
